<?php 
namespace xfyzf\admin\controller;
use lib\XFDB;
use xfyzf\api\controller\Examine;
class ajax1{//get
    public function Set(){
         global $islogin_admin,$CACHE;
         if($islogin_admin!=1)exitjson(-1,'请先登录');
         foreach($_POST as $k=>$v){
        		saveSetting($k, $v);
        	}
         $ad=$CACHE->clear();
         createLog('admin','修改设置状态',http_ip());	
         if($ad){
           exitjson(1,'修改成功');
           }else{
              exitjson(-1,'修改失败'); 
           }
    }
    //订单列表
    public function ordergetDataList(){
         global $islogin_admin,$DB;
         if($islogin_admin!=1)exitjson(-1,'请先登录');
         $get = input("get");
         $ispay = $get['ispay'];
    	 $trade_no = $get['trade_no'];
    	 $out_trade_no = $get['out_trade_no'];
    	 $pid = $get['pid'];
    	 $where = "";
    	 if ($ispay) {
    		if ($ispay == "yes") {
    			$where .= "status = '1' and ";
    		} else {
    			$where .= "status = '0' and ";
    		}
    	}
    	if ($trade_no) $where .= "trade_no = '$trade_no' and ";
    	if ($out_trade_no) $where .= "out_trade_no = '$out_trade_no' and ";
    	if ($pid) $where .= "pid = '$pid' and ";
    	if ($where == "") $where = "1";
    	$where = rtrim($where, " and");
    	$sql = "select count(*) as count from pay_order where {$where}";
    	$getCount = executeSQLQuery($sql)['count'];
    	$pagesize = $get['limit'];
    	$pages = ceil($getCount / $pagesize);
    	$page = isset($get['page']) ? intval($get['page']) : 1;
    	$offset = $pagesize * ($page - 1);
    	$order = "order by addtime desc limit {$offset},{$pagesize}";
    	$sql = $DB->query("SELECT * FROM pay_order where {$where} {$order}");
    	while ($res = $sql->fetch()) {
    		$data[] = $res;
    	}
    	exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function orderstatus(){
        global $islogin_admin,$date;
        if($islogin_admin!=1)exitjson(-1,'请先登录');
        $trade_no = input("post")['id'];
        $sql = "select * from pay_order where trade_no='$trade_no' limit 1";
        $row = executeSQLQuery($sql);
        if(!$row)exitjson(-1,'订单号不存在');
        if ($row['status'] == 1) {
            $sql = "update pay_order set status=0 where trade_no='$trade_no' limit 1";
        }else{
            $sql = "update pay_order set status=1, endtime='$date' where trade_no='$trade_no' limit 1";
        }
        if(executeSQLQuery($sql, 'update'))exitjson(200,'更新状态成功！');
        exitjson(-1,'更新状态失败');
    }
    public function orderdelete(){
        global $islogin_admin;
        if($islogin_admin!=1)exitjson(-1,'请先登录');
        $trade_no = trim(input("post")['id']);
        $sql = "select * from pay_order where trade_no='$trade_no' limit 1";
        $row = executeSQLQuery($sql);
        if(!$row)exitjson(-1,'订单号不存在删除失败');
        $sql = "DELETE FROM pay_order WHERE trade_no='$trade_no'";
        if(executeSQLQuery($sql, 'delete')){
            createLog('admin','删除订单成功',http_ip());	
            exitjson(200,'删除成功！');
        }
        exitjson(-1,'删除失败!');
    }
    public function orderbatchRemove(){
        global $islogin_admin;
        if($islogin_admin!=1)exitjson(-1,'请先登录');
        $id = explode(",", trim(input("post")['ids']));
        $count = count($id);
        $succ = 0;
        createLog('admin','批量删除订单成功',http_ip());
        foreach ($id as $v) {
            $sql = "DELETE FROM pay_order WHERE trade_no='$v'";
    		if (executeSQLQuery($sql, 'delete')) {
    			$succ++;
    		}
    	}
    	if($succ == $count){
    	    exitjson(200,'删除成功');
    	}else{
    	     exitjson(-1,'删除失败');
    	}
    }
    public function orderallRemove(){
        global $islogin_admin;
        if($islogin_admin!=1)exitjson(-1,'请先登录');
         $sql = "SELECT COUNT(*) as count FROM pay_order WHERE status ='2'";
         $recordCount = executeSQLQuery($sql)['count'];
         if($recordCount>0){
              $sql = "DELETE FROM pay_order WHERE status='2'";
              if(executeSQLQuery($sql, 'delete')){
                   createLog('admin','一键删除 未支付订单成功',http_ip());
                   exitjson(200,'删除成功');
              }else{
                  exitjson(-1,'删除失败');
              }
         }else{
             exitjson(-1,'无未支付订单删除失败！');
         }
    }
   public function usergetDataList() {
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
        $type = $get['type'];
        $msg = $get['msg'];
        
        $where = [];
        $params = [];
    
        if (!empty($type) && $msg !==false) {
            if ($type == 'pid' || $type == 'qq') {
                $where[] = "`$type` = :msg";
                $params['msg'] = $msg;
            }
        }
    
        $whereClause = !empty($where) ? "WHERE " . implode(" AND ", $where) : "";
        $sql_count = "SELECT COUNT(*) AS count FROM pay_user  $whereClause";
        $count_result = safeSqlQuery($sql_count, $params, 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        // 构建 SQL 查询
        $sql = "SELECT * FROM pay_user $whereClause ORDER BY pid DESC LIMIT {$offset}, {$pagesize}";
        
        // 执行安全的 SQL 查询
        $result = safeSqlQuery($sql, $params, 'select');
    
        // 获取数据和数量
        $data = $result['result'];

        // 对数据进行处理
        foreach ($data as &$res) {
            $res['smstatus'] = $res['smstatus'];
            $alipay_cookie_ok = safeSqlQuery("SELECT COUNT(*) as num FROM pay_qrlist WHERE status='1' AND type='alipay' AND `pid`=:pid", ['pid' => $res['pid']], 'select')['result']['0']['num'];
            $wxpay_cookie_ok = safeSqlQuery("SELECT COUNT(*) FROM pay_qrlist WHERE status='1' AND type='wxpay' AND `pid`=:pid", ['pid' => $res['pid']], 'select')['result']['0']['num'];
            $qqpay_cookie_ok = safeSqlQuery("SELECT COUNT(*) FROM pay_qrlist WHERE status='1' AND type='qqpay' AND `pid`=:pid", ['pid' => $res['pid']], 'select')['result']['0']['num'];
            $lastday = date("Y-m-d", strtotime("-1 day")) . ' 00:00:00';
            $today = date("Y-m-d") . ' 00:00:00';
            $orders_lastday_yes = safeSqlQuery("SELECT COALESCE(SUM(price), 0) as num FROM pay_order WHERE `pid`=:pid AND status=1 AND addtime>=:today", ['pid' => $res['pid'], 'today' => $today], 'select')['result']['0']['num'];
           
            $orders_today_yes = safeSqlQuery("SELECT COALESCE(SUM(price), 0) as num FROM pay_order WHERE `pid`=:pid AND status=1 AND addtime>=:lastday AND addtime<=:today", ['pid' => $res['pid'], 'lastday' => $lastday, 'today' => $today], 'select')['result']['0']['num'];
            $orders_yes = safeSqlQuery("SELECT COALESCE(SUM(price), 0) as num FROM pay_order WHERE `pid`=:pid AND status=1", ['pid' => $res['pid']], 'select')['result']['0']['num'];
            $alipay_cookie_no = safeSqlQuery("SELECT COUNT(*) as num FROM pay_qrlist WHERE status!='1' AND type='alipay' AND `pid`=:pid", ['pid' => $res['pid']], 'select')['result']['0']['num'];
            $wxpay_cookie_no = safeSqlQuery("SELECT COUNT(*) as num FROM pay_qrlist WHERE status!='1' AND type='wxpay' AND `pid`=:pid", ['pid' => $res['pid']], 'select')['result']['0']['num'];
            $qqpay_cookie_no = safeSqlQuery("SELECT COUNT(*)  as num FROM pay_qrlist WHERE status!='1' AND type='qqpay' AND `pid`=:pid", ['pid' => $res['pid']], 'select')['result']['0']['num'];
            $res['pid'] = $res['pid'] . '/' . $res['key'];
            $res['user'] = ($res['user'] ? $res['user'] : '未设置') . '/' . ($res['pass'] ? $res['pass'] : '未设置');
            $res['qq'] = $res['qq'] . '/' . $res['money'];
            $res['qxqr'] = '支付宝正常：' . ($alipay_cookie_ok ? $alipay_cookie_ok : '0') . ' 失效：' . ($alipay_cookie_no ? $alipay_cookie_no : '0') . "\n";
            $res['qxqr'] .= 'QQ正常：' . ($qqpay_cookie_ok ? $qqpay_cookie_ok : '0') . ' 失效：' . ($qqpay_cookie_no ? $qqpay_cookie_no : '0');
            $res['qxqr'] .= '微信正常：' . ($wxpay_cookie_ok ? $wxpay_cookie_ok : '0') . ' 失效：' . ($wxpay_cookie_no ? $wxpay_cookie_no : '0');
            $res['mghy'] = '支付宝：' . ($res['alipay_free_vip_time'] > $date ? $res['alipay_free_vip_time'] : '未开通或到期了哦') . ' / ';
            $res['mghy'] .= 'QQ：' . ($res['qqpay_free_vip_time'] > $date ? $res['qqpay_free_vip_time'] : '未开通或到期了哦') . ' / ';
            $res['mghy'] .= '微信：' . ($res['wxpay_free_vip_time'] > $date ? $res['wxpay_free_vip_time'] : '未开通或到期了哦');
            $res['sktj'] = '今日收款：' . $orders_lastday_yes . '元 / 昨日收款：' . $orders_today_yes . '元 / 总收款：' . $orders_yes . '元';
        }
    
        // 输出 JSON 数据
        exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
   public function userstatus(){
       global $islogin_admin;
       if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $id = explode("/",input("post")['id'])[0];
        $sql = "select * from pay_user where pid='$id' limit 1";
        $row = executeSQLQuery($sql);
        if(!$row)exitjson(-1,'用户不存在');
        if ($row['zt'] == 1){
            $sql = "update `pay_user` set `zt`='0' where pid='$id' limit 1";
        }else{
            $sql = "update `pay_user` set `zt`='1' where pid='$id' limit 1";
        }
        if(executeSQLQuery($sql, 'update'))exitjson(200,'更新状态成功');
        exitjson(500,'更新状态失败');
   }
   public function Add_user(){
       global $islogin_admin,$date;
       if ($islogin_admin != 1) exitjson(-1, '请先登录');
       $postData = input("input");
       $qq= $postData['qq'];
       $email= $postData['email'];
       $money= $postData['money'];
       $qr_nums= $postData['qr_nums'];
       $user   = $postData['user'];
       $pass   =   $postData['pass'];
       $pay_pass = $postData['pay_pass'];
       if(empty($qq) || empty($email) || empty($user) || empty($pass))exitjson(-1,'必填项不可为空');
       if (strlen($pass) < 6) exitjson(500, "密码长度不能少于6位");
       if (ctype_digit($pass))exitjson(500, "密码过于简单，请使用包含字母、数字和特殊字符的更复杂密码");
       $pass   =   md5(md5($pass));
       $pay_pass = md5(md5($pay_pass));
       $sql = "select * from pay_user where  `qq`='$qq' limit 1";
       if(executeSQLQuery($sql))exitjson(-1,'该QQ已存在 请勿重复添加');
       $sql = "select * from pay_user where  `email`='$email' limit 1";
       if(executeSQLQuery($sql))exitjson(-1,'该邮箱已存在 请勿重复添加');
       $sql = "select * from pay_user where  `user`='$user' limit 1";
       if(executeSQLQuery($sql))exitjson(-1,'该用户名已存在 请勿重复添加');
       $pid='1'.mt_rand(10000000,99999999);
       $key= md5('1'.mt_rand(10000000,99999999).$qq);
       $sql = "INSERT INTO `pay_user` (`pid`,`key`, `user`,`pass`,`pay_pass`,`qq`, `email`,`money`,`qr_nums`,`addtime`) VALUES ('{$pid}','{$key}','{$user}','{$pass}','{$pay_pass}','{$qq}','{$email}','{$money}','{$qr_nums}','{$date}')";
     $result = executeSQLQuery($sql, 'insert');
     if($result){
         createLog('admin','添加用户成功！',http_ip());
         exitjson(200,'添加用户成功');
     }
     exitjson(500,'添加用户失败');
   }
   public function Edit_gaimi(){
       global $islogin_admin;
       if ($islogin_admin != 1) exitjson(-1, '请先登录');
       $postdata = input("input");
       $pid = $postdata['id'];
       $pass = $postdata['pass'];
       $pay_pass = $postdata['pay_pass'];
       if(empty($pid) || empty($pass) || empty($pay_pass))exitjson(-1,'所有内容不可为空！');
        $sql = "SELECT * FROM `pay_user` WHERE `pid`='{$pid}' limit 1";
        $row = executeSQLQuery($sql);
        if(!$row)exitjson(-1,'该用户不存在 请核对后在试');
        if (strlen($pass) < 6) exitjson(500, "密码长度不能少于6位");
        if (ctype_digit($pass))exitjson(500, "密码过于简单，请使用包含字母、数字和特殊字符的更复杂密码");
        $pass   =   md5(md5($pass));
        $pay_pass = md5(md5($pay_pass));
        $sql = "update `pay_user` set `pass`='{$pass}',`pay_pass`='{$pay_pass}' where pid='{$pid}'";
        if(executeSQLQuery($sql, 'update')){
            createLog('admin','修改用户密码成功！pid：'.$pid,http_ip());
            exitjson(200,'修改用户密码成功');
        }
        exitjson(500,'修改用户失败!');
   }
   public function Edit_user(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
    
        // 获取 POST 数据
        $postdata = input("input");
    
        // 提取所需参数
        $pid = $postdata['id'];
        $qq  = $postdata['qq'];
        $money = $postdata['money'];
        $qr_nums = $postdata['qr_nums'];
        $alipay_free_vip_time = isset($postdata['alipay_free_vip_time']) ? $postdata['alipay_free_vip_time'] : '';
        $qqpay_free_vip_time  = isset($postdata['qqpay_free_vip_time']) ? $postdata['qqpay_free_vip_time'] : '';
        $wxpay_free_vip_time  = isset($postdata['wxpay_free_vip_time']) ? $postdata['wxpay_free_vip_time'] : '';
       
        if (empty($pid) || empty($qq)) exitjson(-1, '必填项不可为空！');
    
        $sql = "SELECT * FROM `pay_user` WHERE `pid` = :pid LIMIT 1";
        $result = safeSqlQuery($sql, ['pid' => $pid]);
        if (!$result['count']) exitjson(-1, '该用户不存在');
        // 更新用户信息
        $sql = "UPDATE `pay_user` SET `qq` = :qq, `money` = :money, `qr_nums` = :qr_nums WHERE `pid` = :pid";
        $params = ['qq' => $qq, 'money' => $money, 'qr_nums' => $qr_nums, 'pid' => $pid];
        $res= safeSqlQuery($sql, $params, 'update');
        if ($alipay_free_vip_time) {
            $alipay_free_vip_time =  $alipay_free_vip_time.date(" H:i:s");
            $sql = "UPDATE `pay_user` SET `alipay_free_vip_time` = :alipay_free_vip_time WHERE `pid` = :pid";
            $params = ['alipay_free_vip_time' => $alipay_free_vip_time, 'pid' => $pid];
           $res= safeSqlQuery($sql, $params, 'update');
        }
        if ($qqpay_free_vip_time) {
            $qqpay_free_vip_time = $qqpay_free_vip_time.date(" H:i:s");
            $sql = "UPDATE `pay_user` SET `qqpay_free_vip_time` = :qqpay_free_vip_time WHERE `pid` = :pid";
            $params = ['qqpay_free_vip_time' => $qqpay_free_vip_time, 'pid' => $pid];
           $res= safeSqlQuery($sql, $params, 'update');
        }
        if ($wxpay_free_vip_time) {
            $wxpay_free_vip_time = $wxpay_free_vip_time.date(" H:i:s");
            $sql = "UPDATE `pay_user` SET `wxpay_free_vip_time` = :wxpay_free_vip_time WHERE `pid` = :pid";
            $params = ['wxpay_free_vip_time' => $wxpay_free_vip_time, 'pid' => $pid];
            $res=safeSqlQuery($sql, $params, 'update');
        }
        if($res){
             createLog('admin','修改用户成功！pid：'.$pid,http_ip());
            exitjson(200,'修改用户成功！');
        }
        exitjson(-1,'修改用户失败！');
    }
    public function userremove(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $pid = explode("/",input("post")['id'])[0];
        if(empty($pid))exitjson(-1,'非法操作！');
        $sql = "SELECT * FROM `pay_user` WHERE `pid`='{$pid}' limit 1";
        if(!executeSQLQuery($sql))exitjson(-1,'用户数据不存在');
        $sql = "DELETE FROM pay_user WHERE pid='$pid'";
        if(executeSQLQuery($sql, 'delete'))exitjson(200,"删除用户成功！");
        exitjson(-1,'删除失败！');
    }
    public function qrlistgetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
        $type = $get['type'];
	    $msg =  $get['msg'];
	    $where = [];
        $params = [];
        if (!empty($type) && $msg !==false) {
            if ($type == 'pid' || $type == 'type' || $type == 'beizhu') {
                $where[] = "`$type` = :msg";
                $params['msg'] = $msg;
            }
        }
        $whereClause = !empty($where) ? "WHERE " . implode(" AND ", $where) : "";
        $sql_count = "SELECT COUNT(*) AS count FROM pay_qrlist  $whereClause";
        $count_result = safeSqlQuery($sql_count, $params, 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        // 构建 SQL 查询
        $sql = "SELECT * FROM pay_qrlist $whereClause ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
        
        // 执行安全的 SQL 查询
        $result = safeSqlQuery($sql, $params, 'select');
        // 获取数据和数量
        $data = $result['result'];
        foreach ($data as &$res){
            $qr_id = $res['id'];
            $today = date("Y-m-d");
            $startTime = $today . " 00:00:00";
            $endTime = $today . " 23:59:59";
            $sql = "SELECT count(*) as count FROM pay_order WHERE addtime >= '$startTime' AND addtime <= '$endTime' AND qr_id='$qr_id'"; //总订单 今日
            $todayPayALLOrder = executeSQLQuery($sql)['count'];
            $sql = "SELECT COALESCE(SUM(money), 0) as count from pay_order WHERE  addtime >= '$startTime' AND addtime <= '$endTime' and qr_id='$qr_id'";
             $todayPayALLMoney = executeSQLQuery($sql)['count'];
            $sql = "SELECT count(*) as count FROM pay_order WHERE addtime >= '$startTime' AND addtime <= '$endTime' AND qr_id='$qr_id' AND status='1'";
            $todayPayTRUEOrder = executeSQLQuery($sql)['count'];
            $sql = "SELECT COALESCE(SUM(money), 0) as count from pay_order WHERE status=1 and addtime >= '$startTime' AND addtime <= '$endTime' and qr_id='$qr_id'";
            $todayPayTRUEMoney =  executeSQLQuery($sql)['count'];
            $sql = "SELECT count(*) as count FROM pay_order WHERE addtime >= '$startTime' AND addtime <= '$endTime' AND qr_id='$qr_id' AND status!='1'";
            $todayPayfalseOrder = executeSQLQuery($sql)['count'];
            $sql = "SELECT COALESCE(SUM(money), 0) as count from pay_order WHERE  addtime >= '$startTime' AND addtime <= '$endTime' and qr_id='$qr_id' AND status!='1'";
             $todayPayfalseMoney = executeSQLQuery($sql)['count'];
            if ($todayPayALLOrder > 0){
                $successOrderRate = ($todayPayTRUEOrder / $todayPayALLOrder) * 100;
            }else{
                $successOrderRate = 0;
            }
            $todayPaySuccess = number_format($successOrderRate, 2); 
            
            $currentYear = date("Y");
            $currentMonth = date("m");
            //本月
            $firstDayOfMonth = date("Y-m-01", strtotime("$currentYear-$currentMonth-01"));
            $lastDayOfMonth = date("Y-m-t", strtotime("$currentYear-$currentMonth-01"));
            $sql= "SELECT COUNT(*) as count FROM pay_order WHERE  addtime >= '$firstDayOfMonth' AND addtime <= '$lastDayOfMonth' and qr_id='$qr_id'";
            $monthALLOrder = executeSQLQuery($sql)['count'];
            $sql = "SELECT COALESCE(SUM(money), 0) as count from pay_order WHERE  addtime >= '$firstDayOfMonth' AND addtime <= '$lastDayOfMonth' and qr_id='$qr_id'";
            $monthPayALLMoney = executeSQLQuery($sql)['count'];
            $sql = "SELECT count(*) as count FROM pay_order WHERE addtime >= '$firstDayOfMonth' AND addtime <= '$lastDayOfMonth' AND qr_id='$qr_id' AND status='1'";
            $monthPayTRUEOrder = executeSQLQuery($sql)['count'];
            $sql = "SELECT COALESCE(SUM(money), 0) as count from pay_order WHERE status=1 and addtime >= '$firstDayOfMonth' AND addtime <= '$lastDayOfMonth' and qr_id='$qr_id'";
            $monthPayTRUEMoney =  executeSQLQuery($sql)['count'];
            $sql = "SELECT count(*) as count FROM pay_order WHERE addtime >= '$firstDayOfMonth' AND addtime <= '$lastDayOfMonth' AND qr_id='$qr_id' AND status!='1'";
            $monthPayfalseOrder = executeSQLQuery($sql)['count'];
            $sql = "SELECT COALESCE(SUM(money), 0) as count from pay_order WHERE  addtime >= '$firstDayOfMonth' AND addtime <= '$lastDayOfMonth' and qr_id='$qr_id' AND status!='1'";
             $monthPayfalseMoney = executeSQLQuery($sql)['count'];
             if ($monthALLOrder > 0) {
                $monthPaySuccess = ($monthPayTRUEOrder / $monthALLOrder) * 100;
            } else {
               $monthPaySuccess = 0; // 避免除以零错误
            }
             $monthPaySuccess = number_format($monthPaySuccess, 2); 
             
             
             
             
            $res['todayO'] = '总订单：'.$todayPayALLOrder.' 已完成：'.$todayPayTRUEOrder.' 未完成：'.$todayPayfalseOrder.' 成功率：'.$todayPaySuccess.'%';
            $res['todayP'] = '总金额：'.$todayPayALLMoney.' 已付款：'.$todayPayTRUEMoney.' 未付款：'.$todayPayfalseMoney;
            
            $res['monthO'] = '总订单：'.$monthALLOrder.' 已完成：'.$monthPayTRUEOrder.' 未完成：'.$monthPayfalseOrder.' 成功率：'.$monthPaySuccess.'%';
            $res['monthp'] = '总金额：'.$monthPayALLMoney.' 已付款：'.$monthPayTRUEMoney.' 未付款：'.$monthPayfalseMoney;
            $res['times']  = '状态：'.cookie_zt($res['status'], $res['type'], $res['addtime'], $res['endtime'], $res['wx_name'], $res['hook_type'], $res['crontime'], $res['cookie'], $res['xf_stat'],$res['xf_type']);
    		if(empty($res['beizhu']))$res['beizhu'] = '暂无备注';
        }
        exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function qrlistdelete(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $id = input("post")['id'];
        if(empty($id))exitjson(-1,'非法操作！');
        $sql = "SELECT * FROM `pay_qrlist` WHERE `id`='{$id}' limit 1";
        if(!executeSQLQuery($sql))exitjson(-1,'二维码数据不存在');
        $sql = "DELETE FROM pay_qrlist WHERE id='$id'";
        if(executeSQLQuery($sql, 'delete'))exitjson(200,"删除二维码数据成功！");
        exitjson(-1,'删除失败！');
    }
    public function PackagegetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
        $sql_count = 'SELECT COUNT(*) AS count FROM pay_package WHERE 1';
        $count_result = safeSqlQuery($sql_count, [], 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        $order = "ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
        $sql_select = "SELECT * FROM pay_package {$order}";
        $select_result = safeSqlQuery($sql_select, [], 'select');
        $data = [];
        foreach ($select_result['result'] as $res) {
            $data[] = $res;
        }
    	exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function add_Package(){
         global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata = input("input");
        $name = $postdata['name'];
        $days = $postdata['days'];
        $quota = $postdata['quota'];
        $price = $postdata['price'];
        $introduce = $postdata['introduce'];
        if(empty($name) || empty($days) || empty($quota) || empty($price) || empty($introduce))exitjson(-1,'所有内容不可为空');
        $sql_insert_package = "INSERT INTO pay_package (name, days, quota, price, introduce) VALUES (:name, :days, :quota, :price, :introduce)";
        $params = [
            'name' => $name,
            'days' => $days,
            'quota' => $quota,
            'price' => $price,
            'introduce' => $introduce
        ];
        $insert_result = safeSqlQuery($sql_insert_package, $params, 'insert');
        if($insert_result)exitjson(200,'添加套餐成功！');
        exitjson(-1,'添加套餐失败！');
    }
    public function edit_Package(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata = input("input");
        $id   = $postdata['id'];
        $name = $postdata['name'];
        $days = $postdata['days'];
        $quota = $postdata['quota'];
        $price = $postdata['price'];
        $introduce = $postdata['introduce'];
        if(empty($name) || empty($days) || empty($quota) || empty($price) || empty($introduce) || empty($id))exitjson(-1,'所有内容不可为空');
        $sql = "SELECT * FROM `pay_package` WHERE `id`='{$id}' limit 1";
        if(!executeSQLQuery($sql))exitjson(-1,'套餐数据不存在');
        $sql = "update `pay_package` set `name`='{$name}',`days`='{$days}',`quota`='{$quota}',`price` ='{$price}',`introduce` ='{$introduce}' where `id`='{$id}'";
        if(executeSQLQuery($sql, 'update'))exitjson(200,'修改套餐成功');
        exitjson(-1,'修改失败！');
        
    }
    public function Wechat_TrumpetgetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
        $sql_count = 'SELECT COUNT(*) AS count FROM pay_wechat_trumpet WHERE 1';
        $count_result = safeSqlQuery($sql_count, [], 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        $order = "ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
        $sql_select = "SELECT * FROM pay_wechat_trumpet {$order}";
        $select_result = safeSqlQuery($sql_select, [], 'select');
        $data = [];
        foreach ($select_result['result'] as $res) {
            $res['active'] = wachat_login_zt($res['login_time']);
            
            $data[] = $res;
        }
        exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function Add_Wechet_Tp(){
        global $islogin_admin,$date;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata = input("post");
        $mode     = $postdata['mode'];
        $wx_user  = $postdata['wx_user'];
        $wx_name  = $postdata['wx_name'];
        $beizhu   = $postdata['beizhu'];
        $sort     = $postdata['sort'];
        if(empty($mode) || empty($wx_user) || empty($wx_name) || empty($sort))exitjson(-1,'必选项不可为空！');
        $time=time();
	    $sid=md5(time());
	    $sql = "INSERT INTO `pay_wechat_trumpet` (`wx_user`,`wx_name`,`beizhu`, `sort`, `login_time`,`status`,`addtime`,`mode`,`sid`) VALUES ('{$wx_user}','{$wx_name}','{$beizhu}','{$sort}','{$time}','0','{$date}','{$mode}','{$sid}')";
	    if(executeSQLQuery($sql, 'insert'))exitjson(200,"添加成功！");
	    exitjson(-1,'添加失败！');
    }
    public function Edit_Wechet_Tp(){
        global $islogin_admin,$date;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata = input("post");
        $id       = $postdata['id'];
        $wx_user  = $postdata['wx_user'];
        $wx_name  = $postdata['wx_name'];
        $beizhu   = $postdata['beizhu'];
        $sort     = $postdata['sort'];
        if(empty($id) || empty($wx_user) || empty($wx_name) || empty($sort))exitjson(-1,'所有内容不可为空');
        $sql = "SELECT * FROM `pay_wechat_trumpet` WHERE `id`='{$id}' limit 1";
        if(!executeSQLQuery($sql))exitjson(-1,'店员数据不存在！');
        $sql = "update `pay_wechat_trumpet` set `wx_user`='{$wx_user}',`wx_name`='{$wx_name}',`beizhu`='{$beizhu}',`sort` ='{$sort}' where id='{$id}'";
        if(executeSQLQuery($sql, 'update'))exitjson(200,'修改店员数据成功！');
        exitjson(-1,'修改失败！');
    }
    public function RiskgetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get  = input("get");
        $type = $get['type'];
	    $msg = $get['msg'];
	    $where = [];
        $params = [];
        if (!empty($type) && $msg !==false){
            if ($type == 'pid' || $type == 'url' || $type == 'content'){
                 $where[] = "`$type` = :msg";
                 $params['msg'] = $msg;
            }
        }
         $whereClause = !empty($where) ? "WHERE " . implode(" AND ", $where) : "";
         $sql_count = "SELECT COUNT(*) AS count FROM pay_risk  $whereClause";
         $count_result = safeSqlQuery($sql_count, $params, 'select');
         $getCount = $count_result['result'][0]['count'];
         $pagesize = $get['limit'];
         $pages = ceil($getCount / $pagesize);
         $page = isset($get['page']) ? intval($get['page']) : 1;
         $offset = $pagesize * ($page - 1);
        // 构建 SQL 查询
         $sql = "SELECT * FROM pay_risk $whereClause ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
         $result = safeSqlQuery($sql, $params, 'select');
         $data = $result['result'];
         exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function LoggetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
        $type = $get['type'];
	    $msg = $get['msg'];
	    $where = [];
        $params = [];
        if (!empty($type) && $msg !==false){
            if ($type == 'pid' || $type == 'ip'){
                 $where[] = "`$type` = :msg";
                 $params['msg'] = $msg;
            }
        }
         $whereClause = !empty($where) ? "WHERE " . implode(" AND ", $where) : "";
          $sql_count = "SELECT COUNT(*) AS count FROM pay_log  $whereClause";
         $count_result = safeSqlQuery($sql_count, $params, 'select');
         $getCount = $count_result['result'][0]['count'];
         
         $pagesize = $get['limit'];
         $pages = ceil($getCount / $pagesize);
         $page = isset($get['page']) ? intval($get['page']) : 1;
         $offset = $pagesize * ($page - 1);
        // 构建 SQL 查询
         $sql = "SELECT * FROM pay_log $whereClause ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
         $result = safeSqlQuery($sql, $params, 'select');
         $data = $result['result'];
         exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function NoticegetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
        $sql_count = 'SELECT COUNT(*) AS count FROM pay_notice WHERE 1';
        $count_result = safeSqlQuery($sql_count, [], 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        $order = "ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
        $sql_select = "SELECT * FROM pay_notice {$order}";
        $select_result = safeSqlQuery($sql_select, [], 'select');
        $data = $select_result['result'];
        exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function add_Notice(){
        global $islogin_admin,$date,$conf;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $input      = json_decode(file_get_contents('php://input'), true);
        $postdata   = ($conf['gghtml_code'] == 1)?$input:input("input");
        $sort       = $postdata['sort'];
        $datatxt    = $postdata['datatxt'];
        $color      = $postdata['color'];
        $title      = $postdata['title'];
        if(empty($title) || empty($datatxt) || $sort===false)exitjson(-1,'所有内容不可为空！');
        $sql = "INSERT INTO pay_notice (title,datatxt,sort,color,addtime,status) values ('$title', '$datatxt', '$sort','$color', '$date', 1)";
        if(executeSQLQuery($sql, 'insert'))exitjson(200,"添加成功！");
	    exitjson(-1,'添加失败！');
    }
    public function edit_Notice(){
        global $islogin_admin,$conf;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $input      = json_decode(file_get_contents('php://input'), true);
        $postdata   = ($conf['gghtml_code'] == 1)?$input:input("input");
        $id         = $postdata['id'];
        $title      = $postdata['title'];
        $datatxt    = $postdata['datatxt'];
        $sort       = $postdata['sort'];
        $color      = $postdata['color'];
        if(empty($id) || empty($title) || empty($datatxt) || $sort===false)exitjson(-1,'必选项不可为空！');
        $sql = "SELECT * FROM `pay_notice` WHERE `id`='{$id}' limit 1";
        if(!executeSQLQuery($sql))exitjson(-1,'公告数据不存在！');
        $sql = "UPDATE `pay_notice` SET `title`='$title',`datatxt`='$datatxt',`sort`='$sort',`color`='$color' WHERE `id`='$id'";
        if(executeSQLQuery($sql, 'update'))exitjson(200,'修改公告成功！');
        exitjson(-1,'修改失败！');
    }
    public function downgetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
         $sql_count = 'SELECT COUNT(*) AS count FROM pay_down WHERE 1';
        $count_result = safeSqlQuery($sql_count, [], 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        $order = "ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
        $sql_select = "SELECT * FROM pay_down {$order}";
        $select_result = safeSqlQuery($sql_select, [], 'select');
        $data = $select_result['result'];
        exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function add_down(){
        global $islogin_admin,$date;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata  = input("input");
        $name      = $postdata['name'];
        $url       = $postdata['url'];
        $readme    = $postdata['readme'];
        if(empty($name) || empty($url) || empty($readme))exitjson(-1,'必选项不可为空！');
        $sql = "insert into `pay_down` (`name`,`url`,`readme`,`addtime`) values ('".$name."','".$url."','".$readme."','".$date."')";
        if(executeSQLQuery($sql, 'insert'))exitjson(200,"添加成功！");
	    exitjson(-1,'添加失败！');
    }
    public function edit_down(){
         global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata  = input("input");
        $id        = $postdata['id'];
        $name      = $postdata['title'];
        $url       = $postdata['url'];
        $readme    = $postdata['readme'];
        if(empty($id) || empty($name) || empty($url) || empty($readme))exitjson(-1,'必选项不可为空！');
        $sql = "SELECT * FROM `pay_down` WHERE `id`='{$id}' limit 1";
        if(!executeSQLQuery($sql))exitjson(-1,'插件数据不存在！');
        $sql = "update `pay_down` set `name` ='{$name}',`url` ='{$url}',`readme` ='{$readme}' where `id`='$id'";
        if(executeSQLQuery($sql, 'update'))exitjson(200,'修改插件信息成功！');
        exitjson(-1,'修改失败！');
    }
    public function WorkgetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
         $sql_count = 'SELECT COUNT(*) AS count FROM pay_work WHERE 1';
        $count_result = safeSqlQuery($sql_count, [], 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        $order = "ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
        $sql_select = "SELECT * FROM pay_work {$order}";
        $select_result = safeSqlQuery($sql_select, [], 'select');
        $data = $select_result['result'];
        exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $data], 320));
    }
    public function edit_Huifu(){
        global $islogin_admin,$date,$httphost,$conf;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata = input("input");
        $id  = $postdata['id'];
        $huifu = $postdata['huifu'];
        if(empty($id) || empty($huifu))exitjson(-1,'回复的内容不可为空！');
        $sql="select * from pay_work where id='$id'  limit 1";
        $res=executeSQLQuery($sql); 
        if(!$res)exitjson(-1,'工单不存在');
        if($res['active'] == 1)exitjson(-1,'该工单已回复 请勿重复回复');
        $sql="select * from pay_user where `pid`='".$res['uid']."'  limit 1";
         $userrow = executeSQLQuery($sql); 
         $sql = "update `pay_work` set `huifu` ='{$huifu}',`wdata` ='{$date}',`active` ='1' where `id`='$id'";
         if(executeSQLQuery($sql, 'update')) {
             $qqemail=$res['qq'].'@qq.com';
             $sub = $conf['sitename'].' - 您提交的工单已有回复';
             $data = [
                'user' => $userrow['user'],
                'paragraphs' => [
                    ['label' => '新的工单等您来处理！'],
                    ['label' => '尊敬的商户您好【'.$conf['sitename'].'】对你的工单进行了回复'],
                    ['label' => '工单编号为：', 'value' => $res['num'].'的工单已经有最新的进展啦！','fontSize'=>'12'],
                    ['label' => '请尽快登录网站查看详细内容', 'value' => '【<a href="'.$httphost.'" target="_blank">登录网站</a>】<br/>','fontSize'=>'12'],
                ]
            ];
            $msg = Mailbox_sending_template($data, '工单回复'); 
            $result = send_mail($qqemail, $sub, $msg);
            exitjson(200,'回复成功');
         }
         exitjson(-1,'回复失败！');
    }
    public function updatePwd(){
         global $islogin_admin,$conf,$CACHE;
         if ($islogin_admin != 1) exitjson(-1, '请先登录');
         $postdata  = input("post");
         $olduser   = $postdata['olduser'];
         $newuser   = $postdata['newuser'];
         $oldpwd    = $postdata['oldpwd'];
         $newpwd    = $postdata['newpwd'];
         if(empty($olduser) || empty($newuser) || empty($oldpwd) || empty($newpwd)) exitjson(-1,'所有内容不可为空！');
         if($oldpwd == $newpwd) exitjson(-1,'新密码和旧密码不能一致！');
         if($olduser != $conf['admin_user'])exitjson(-1,'旧用户名错误！');
         if($conf['admin_pass'] != md5(md5($oldpwd)))exitjson(-1,'旧密码错误！');
         if($conf['admin_pass'] == md5(md5($newpwd)))exitjson(-1,'新密码不能和历史密码 一致');
         if (strlen($newpwd) < 6 || ctype_digit($newpwd))exitjson(500, "新密码过于简单，请使用包含字母、数字和特殊字符的更复杂密码");
         $pwd = md5(md5($newpwd));
         
         if($olduser == $newuser){
             saveSetting('admin_pass',$pwd);
	         $ad=$CACHE->clear();
	         if($ad){
	             setcookie("admin_token", "", time() - 99999999999999999);
	             exitjson(200,'修改成功！');
	         }
	         exitjson(-1,'修改失败'); 
         }else{
             saveSetting('admin_pass',$pwd);
             saveSetting('admin_user',$newuser);
              $ad=$CACHE->clear();
              if($ad){
                  setcookie("admin_token", "", time() - 99999999999999999);
	              exitjson(200,'修改成功！');
              }
              exitjson(-1,'修改失败'); 
         }
    }
    public function qunemailgetDataList(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $get = input("get");
        $sql_count = 'SELECT COUNT(*) AS count FROM pay_email WHERE 1';
        $count_result = safeSqlQuery($sql_count, [], 'select');
        $getCount = $count_result['result'][0]['count'];
        $pagesize = $get['limit'];
        $pages = ceil($getCount / $pagesize);
        $page = isset($get['page']) ? intval($get['page']) : 1;
        $offset = $pagesize * ($page - 1);
        $order = "ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
        $sql_select = "SELECT * FROM pay_email {$order}";
        $select_result = safeSqlQuery($sql_select, [], 'select');
        $modified_data = [];
        foreach($select_result['result'] as &$data) {
            $data['pid'] = (!empty($data['pid'])) ? $data['pid']  : "非本站用户";
            $data['mailname'] = (!empty($data['mailname'])) ? $data['mailname'] : "未知";
           $data['type'] = ($data['type'] ==  1) ? "<font color=green>发信成功</font>" : "<font color=red>发信失败</font>";
           
            $modified_data[] = $data;
        }
        exit(json_encode(['code' => 0, 'msg' => "ok", "count" => $getCount, "data" => $modified_data], 320));
    }
    public function add_email(){
        global $islogin_admin,$date;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata   = input("input");
        $postdata   = array_filter($postdata, function($value) {
            return $value !== null && $value !== '';
        });
        $user_type  = $postdata['user_type'];
        $mail_title = $postdata['mail_title'];
        $mail_content = $postdata['mail_content'];
        
        if(empty($user_type))exitjson(-1,'请选择发信类型！');
        if(empty($mail_title) || empty($mail_content))exitjson(-1,'发信标题和发信内容不可为空');
        $success_count = 0; // 成功发送的计数器
        $error_count = 0; // 发送失败的计数器
        switch($user_type){
            case '1':
                $sql = "SELECT email,pid FROM pay_user";
                $select_result = safeSqlQuery($sql, [], 'select');
                
                foreach($select_result['result'] as $data){
                    
                    if(!empty($data['email'])){
                        $email = $data['email'];
                        try{
                            $is_sent_successfully = send_mail($email, $mail_title, $mail_content);
                            if ($is_sent_successfully) {
                                $success_count++;
                                $code = 1;
                            } else {
                                $error_count++;
                                $code = 0;
                            }
                            $sql = "INSERT INTO `pay_email` (`mailname`, `pid`, `mailtitle`, `time`, `type`) VALUES ('{$email}', '{$data['pid']}','{$mail_title}', '{$date}', '{$code}')";
                            executeSQLQuery($sql, 'insert');
                            
                        }catch (Exception $e) {
                             $error_count++;
                             $sql = "INSERT INTO `pay_email` (`mailname`, `pid`, `mailtitle`, `time`, `type`) VALUES ('{$email}', '{$data['pid']}','{$mail_title}', '{$date}', '0')";
                             executeSQLQuery($sql, 'insert');
                        }
                    }
                }
                exitjson(200, "全部执行完毕，成功发信邮件{$success_count}个，发信失败邮件{$error_count}个。");
            break;
            case '2':
                if(empty($postdata['mail_email']))exitjson(-1,'发信邮箱不可为空！');
                $email_arr = explode(',', $postdata['mail_email']);
                foreach ($email_arr as $email) {
                    if(filter_var($email, FILTER_VALIDATE_EMAIL)){
                        $is_sent_successfully = send_mail($email, $mail_title, $mail_content); 
                        if ($is_sent_successfully) {
                            $success_count++;
                            $code = 1;
                        } else {
                            $error_count++;
                            $code = 0;
                        }
                        $sql = "INSERT INTO `pay_email` (`mailname`, `pid`, `mailtitle`, `time`, `type`) VALUES ('{$email}', '非平台用户','{$mail_title}', '{$date}', '{$code}')";
                        executeSQLQuery($sql, 'insert');
                    }else{
                        $sql = "INSERT INTO `pay_email` (`mailname`, `pid`, `mailtitle`, `time`, `type`) VALUES ('{$email}', '非平台用户','{$mail_title}', '{$date}', '0')";
                        executeSQLQuery($sql, 'insert');
                    }
                }
                exitjson(200, "全部执行完毕，成功发信邮件{$success_count}个，发信失败邮件{$error_count}个。"); 
            break;
        }
    }
    
    //微信云端列表
    public function wxyunurlgetDataList(){
        $data = XFDB::wxyunurllist();
        Examine::exitjson(0,'success',$data);
    }
    public function Add_wxyunurl(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
       $postData = input("input");
       $name     = $postData['name'];
       $url      = $postData['url'];
       $code     = $postData['code'];
       if(Examine::checkRequiredParams(array($name,$url,$code),true))exitjson(-1,'必填项不可为空！');
       if(XFDB::wxyunurlrow($url,'url'))exitjson(-1,'该云端地址存在请核对后在试！');
        $sql = "INSERT INTO `pay_wxyunurl` (`url`, `name`, `code`,`status`) VALUES ('{$url}','{$name}','{$code}','1')";
        if(executeSQLQuery($sql, 'insert'))exitjson(200,'添加成功！');
        exitjson(-1,'添加失败！');
    }
    public function Edit_wxyunurl(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $postdata = input("input");
        $id       = $postdata['id'];
        $name     = $postdata['name'];
        $url      = $postdata['url'];
        $code     = $postdata['code'];
        if(Examine::checkRequiredParams(array($id,$name,$url,$code),true))exitjson(-1,'必填项不可为空！');
        $wxyunrow = XFDB::wxyunurlrow($id);
        if(!$wxyunrow)exitjson(-1,'该链接不存在！');
        $sql = "update `pay_wxyunurl` set `code` ='{$code}',`name` ='{$name}',`url` ='{$url}' where `id`='{$id}' ";
        if(executeSQLQuery($sql, 'update'))exitjson(200,'修改成功！');
        exitjson(-1,'修改失败！');
    }
    public function wxyunurlremove(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $id  = input("post")['id'];
        if(empty($id))exitjson(-1,'非法操作！');
        if(XFDB::qrlistrow($id,'wxyunurl'))exitjson(-1,'该云端已绑定数据 删除失败');
        $wxyunrow = XFDB::wxyunurlrow($id);
        if(!$wxyunrow)exitjson(-1,'该数据不存在');
        $sql = "DELETE FROM pay_wxyunurl WHERE `id` ='$id'";
        if(executeSQLQuery($sql, 'delete')){
            exitjson(200,"删除成功！");
        }
         exitjson(-1,'删除失败！');
    }
    public function wxyunurlstatus(){
        global $islogin_admin;
        if ($islogin_admin != 1) exitjson(-1, '请先登录');
        $id  = input("post")['id'];
        if(empty($id))exitjson(-1,'非法操作！');
        $wxyunrow = XFDB::wxyunurlrow($id);
        if(!$wxyunrow)exitjson(-1,'该云端不存在！');
        if(XFDB::qrlistrow($id,'wxyunurl'))exitjson(-1,'该云端已绑定数据 修改状态失败');
        $status = ($wxyunrow['status'] == 1)?0:1;
        $sql = "update `pay_wxyunurl` set `status`='".$status."' where `id`='$id' limit 1";
        if(executeSQLQuery($sql, 'update'))exitjson(200,'更新状态成功');
        exitjson(500,'更新状态失败');
    }
}

?>